package cn.xyy.common.domain.system.auth;

import cn.xyy.common.annotation.jdbc.Columns;
import cn.xyy.common.annotation.jdbc.Tables;

import java.util.List;

/**
 * 系统权限
 * 
 * @author xyy
 *
 */
@Tables("t_sys_permission")
public class Permission {

	@Columns(value = "perm_id", primaryKey = true)
	private Integer id;
	@Columns("parent_id")
	private Integer parentId;

	@Columns("title")
	private String title;

	@Columns("permission_code")
	private String permissionCode; // 权限标识

	@Columns("types")
	private Integer types; // 0目录 '1:菜单，2:按钮',

	@Columns("status")
	private Integer status;

	@Columns("description")
	private String description;

	@Columns("path")
	private String path;

	@Columns("levels")
	private Integer levels;
	// 菜单顺序
	@Columns("sorts")
	private Integer sorts;

	@Columns("i_frame")
	private Integer iframe;// 是否外链 2不是，1是

	@Columns("name")
	private String name;// 组件名称

	@Columns("component")
	private String component;// 组件路径

	@Columns("icon")
	private String icon;// 图标

	@Columns("cache")
	private Integer cache;// 是否缓存 2:不是 1是

	@Columns("redirect")
	private String redirect;// 跳转
	@Columns("hide")
	private Integer hide;// 隐藏菜单

	@Columns("hide_children")
	private Integer hideChildren;// 隐藏所有子菜单

	// 子权限集合
	private List<Permission> children;

	public boolean isMenu() {
		if (this.types == 0 || this.types == 1) {
			return true;
		}
		return false;
	}

	public boolean isRoot() {
		if (this.parentId == 0) {
			return true;
		}
		return false;
	}

	public boolean isPermission() {
		if (this.types == 2) {
			return true;
		}
		return false;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<Permission> getChildren() {
		return children;
	}

	public void setChildren(List<Permission> children) {
		this.children = children;
	}

	public Integer getId() {
		return id;
	}

	public Permission setId(Integer id) {
		this.id = id;
		return this;
	}

	public Integer getParentId() {
		return parentId;
	}

	public void setParentId(Integer parentId) {
		this.parentId = parentId;
	}

	public Integer getTypes() {
		return types;
	}

	public void setTypes(Integer types) {
		this.types = types;
	}

	public Integer getLevels() {
		return levels;
	}

	public void setLevels(Integer levels) {
		this.levels = levels;
	}

	public Integer getSorts() {
		return sorts;
	}

	public void setSorts(Integer sorts) {
		this.sorts = sorts;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((status == null) ? 0 : status.hashCode());
		result = prime * result + ((types == null) ? 0 : types.hashCode());
		result = prime * result + ((path == null) ? 0 : path.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Permission other = (Permission) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (status == null) {
			if (other.status != null)
				return false;
		} else if (!status.equals(other.status))
			return false;
		if (types == null) {
			if (other.types != null)
				return false;
		} else if (!types.equals(other.types))
			return false;
		if (path == null) {
			if (other.path != null)
				return false;
		} else if (!path.equals(other.path))
			return false;
		return true;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public Integer getIframe() {
		return iframe;
	}

	public void setIframe(Integer iframe) {
		this.iframe = iframe;
	}

	public Integer getCache() {
		return cache;
	}

	public void setCache(Integer cache) {
		this.cache = cache;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getPermissionCode() {
		return permissionCode;
	}

	public void setPermissionCode(String permissionCode) {
		this.permissionCode = permissionCode;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String getComponent() {
		return component;
	}

	public void setComponent(String component) {
		this.component = component;
	}

	public String getRedirect() {
		return redirect;
	}

	public void setRedirect(String redirect) {
		this.redirect = redirect;
	}

	public Integer getHide() {
		return hide;
	}

	public void setHide(Integer hide) {
		this.hide = hide;
	}

	public Integer getHideChildren() {
		return hideChildren;
	}

	public void setHideChildren(Integer hideChildren) {
		this.hideChildren = hideChildren;
	}

}